<template>
  <div class="shop-r-form">
    <h2 class="pancel-title panel-13 flex v-align-c">
      <span></span>
      <i>店主主页入口栏</i>
    </h2>
    <h3 class="pancel-s-title">颜色设置</h3>
    <el-form class="pad-t-15 pad-l-25 pad-r-25 form-diy">
      <div class="border-box near-box flex">
        <div class="flex-item">
          <h4>背景</h4>
          <div class="mar-t-3 mar-b-5">
            <el-form-item>
              <div class="flex font-12 pad-r-30">
                <el-color-picker :predefine="predefineColors" v-model="customPage.homeBackgroundColor" class="color-sel"></el-color-picker>
              </div>
            </el-form-item>
          </div>
        </div>
        <div class="flex-item">
          <h4>文字</h4>
          <div class="mar-t-3 mar-b-5">
            <el-form-item>
              <div class="flex font-12 pad-r-30">
                <el-color-picker :predefine="predefineColors" v-model="customPage.homeFontColor" class="color-sel"></el-color-picker>
              </div>
            </el-form-item>
          </div>
        </div>
      </div>
      <div class="border-box">
        <h4>样式风格</h4>
        <div class="mar-t--5 mar-b--15">
          <el-form-item>
            <div class="font-14">
              <el-row>
                <el-col :span="12">
                  <el-radio v-model="customPage.homeStyle" label="10">风格一</el-radio>
                </el-col>
                <el-col :span="12">
                  <el-radio v-model="customPage.homeStyle" label="11">风格二</el-radio>
                </el-col>
              </el-row>
            </div>
          </el-form-item>
        </div>
      </div>
      <div>
        <el-form-item label="店主名称格式">
            <el-input v-model="customPage.shopNameFormat" placeholder="[店主昵称]"></el-input>
            <span class="font-10 font-gray">示例：[店主昵称]的云店，小程序显示为"众项的云店"</span>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
  import { getStrByLength } from '@/utils'
  import { getToken } from '@/utils/auth'

  export default {
    components: { },
    props: {
      customPage1: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        customPage: {
          pageId: '',
          homeFontColor: '#000000',
          homeBackgroundColor: '#FFFFFF',
          homeStyle: '10',
          shopNameFormat: ''
        },
        fullScreenLoading: null,
        pictureType: '1',
        predefineColors: [],
        test: '店主昵称'
      }
    },
    // 初始化页面
    created() {
      this.resetDetails()
      this.customPage = this.customPage1
      // this.customPage.shopNameFormat = this.customPage1.shopNameFormat ? this.customPage1.shopNameFormat : '店主昵称'
      this.$set(this.customPage, 'homeStyle', this.customPage.homeStyle ? this.customPage.homeStyle.toString() : '10')
      this.token = { accessToken: getToken() }
      this.predefineColors = this.$store.state.globalData.predefineColors
    },
    methods: {
      getStrByLength(str, n) {
        return getStrByLength(str, n)
      },
      handleRemove(file, fileList) {
        console.log(file, fileList)
      },
      handlePictureCardPreview(file) {
        console.log(file)
      },
      beforeUpload(file, item) {
        const isJPG = file.type === 'image/jpeg'
        const isGIF = file.type === 'image/gif'
        const isPNG = file.type === 'image/png'
        const isBMP = file.type === 'image/bmp'
        if (!isJPG && !isGIF && !isPNG && !isBMP) {
          this.$message.error('上传图片必须是JPG/GIF/PNG/BMP 格式!')
        }
        this.fullScreenLoading = this.$loading({
          lock: true,
          text: '加载中',
          background: 'rgba(255, 255, 255, 0.5)'
        })
        return (isJPG || isBMP || isGIF || isPNG)
      },
      handleUploadSuccess(res, index) {
        this.fullScreenLoading.close()
        if (res.code === 101) {
          this.customPage.sharePicture = res.data[0]
          this.$bus.$emit('resetDetailsPage', this.customPage)
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
          return false
        }
      },
      resetDetails() {
        this.customPage = {
          pageId: '',
          homeFontColor: '#000000',
          homeBackgroundColor: '#FFFFFF',
          homeStyle: '10'
        }
      }
    }
  }
</script>
